package com.haoshuang.zhouzhoubang.ui.vm

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.bean.CallBean
import com.haoshuang.zhouzhoubang.model.bean.OrderBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ServiceRecordViewModel : BaseViewModel() {

    val getData = StatefulMutableLiveData<ArrayList<OrderBean>>()
    fun getData(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ArrayList<OrderBean>>("api/master_order/get_team_order_list", *params,
                onStart = {
                    getData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData.value = StateData.Success(it)
                })
        }
    }

    val getUserData = StatefulMutableLiveData<ArrayList<OrderBean>>()
    fun getUserData(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ArrayList<OrderBean>>("api/master_order/get_user_order_list", *params,
                onStart = {
                    getUserData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getUserData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getUserData.value = StateData.Success(it)
                })
        }
    }
}